﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace TurboTemplate
{
    public class ProfileHelper
    {
        public static string ProfileDirectory()
        {
            string appData = Path.Combine(Application.UserAppDataPath, "Profiles");

            if (!Directory.Exists(appData))
                Directory.CreateDirectory(appData);

            return appData;
        }

        public static string GetFileNameForNewProfile(Profile p)
        {
            return Path.Combine(ProfileDirectory(), Guid.NewGuid().ToString()) + ".ttp";
        }

        public static List<Profile> GetProfiles()
        {
            var ret = new List<Profile>();

            // Get our files
            var files = Directory.GetFiles(ProfileDirectory());
            foreach (var s in files)
            {
                ret.Add(s.Load<Profile>());
            }
            ret.Sort((x,y) => x.Name.CompareTo(y.Name));
            ret.Insert(0, Profile.NewProfile);

            return ret;
        }
    }
}
